package euler.p001_050;

import java.util.List;

import euler.MainEuler;
import euler.helper.Pair;

public class Euler047 extends MainEuler {

    /*
        The first two consecutive numbers to have
        two distinct prime factors are:

        14 = 2 × 7
        15 = 3 × 5

        The first three consecutive numbers to have
        three distinct prime factors are:

        644 = 2^2 × 7 × 23
        645 = 3 × 5 × 43
        646 = 2 × 17 × 19.

        Find the first four consecutive integers to have
        four distinct primes factors. What is the first of these numbers?

     */
    public String resolve() {

        int dpf = 4;

        List<Pair<Long, Integer>> pfi_0 = primeHelper.factorizar(2);
        List<Pair<Long, Integer>> pfi_1 = primeHelper.factorizar(3);
        List<Pair<Long, Integer>> pfi_2 = primeHelper.factorizar(4);
        List<Pair<Long, Integer>> pfi_3 = primeHelper.factorizar(5);

        for (int i = 3; i > 0; i++) {
            pfi_0 = pfi_1;
            pfi_1 = pfi_2;
            pfi_2 = pfi_3;
            pfi_3 = primeHelper.factorizar(i + 3);

            if (pfi_0.size() == dpf &&
                    pfi_1.size() == dpf &&
                    pfi_2.size() == dpf &&
                    pfi_3.size() == dpf
            ) {
                return String.valueOf(i);
            }
        }

        return null;
    }

}
